﻿// 功能：实现UiScrollWin控件
// 描述：
// 作者：温伟鹏
// 日期：2010/5/25 16:14:20

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace MeizuSDK.Presentation
{
    /// <summary>
    /// 可以滚动的容器控件（实现UiScrollWin控件）
    /// </summary>
    public class ScrollableControl : Control
    {
        #region DllImport

        [DllImport("MZFCWrapper.dll")]
        private static extern IntPtr UiScrollWinWrapperCtor(MouseEventFunc onLButtonDblClk,
            MouseEventFunc onLButtonDown, MouseEventFunc onLButtonUp, MouseEventFunc onMouseMove);

        [DllImport("MZFCWrapper.dll")]
        private static extern int UiScrollWinWrapperCalcContentHeight(IntPtr pObj);

        [DllImport("MZFCWrapper.dll")]
        private static extern int UiScrollWinWrapperCalcContentTopPosH(IntPtr pObj);

        [DllImport("MZFCWrapper.dll")]
        private static extern int UiScrollWinWrapperCalcContentTopPosV(IntPtr pObj);

        [DllImport("MZFCWrapper.dll")]
        private static extern int UiScrollWinWrapperCalcContentWidth(IntPtr pObj);

        [DllImport("MZFCWrapper.dll")]
        private static extern bool UiScrollWinWrapperIsScrollable(IntPtr pObj);

        [DllImport("MZFCWrapper.dll")]
        private static extern void UiScrollWinWrapperMoveTopPos(IntPtr pObj, int nOffset);

        [DllImport("MZFCWrapper.dll")]
        private static extern void UiScrollWinWrapperScroll(IntPtr pObj, int nOffset);

        [DllImport("MZFCWrapper.dll")]
        private static extern void UiScrollWinWrapperScrollStart(IntPtr pObj, double fScrollSpeed);

        [DllImport("MZFCWrapper.dll")]
        private static extern void UiScrollWinWrapperScrollStop(IntPtr pObj);

        [DllImport("MZFCWrapper.dll")]
        private static extern void UiScrollWinWrapperScrollTo(IntPtr pObj, int nScrollToType, int nDstTopPos, bool bAnimate);

        [DllImport("MZFCWrapper.dll")]
        private static extern void UiScrollWinWrapperSetTopPos(IntPtr pObj, int nTopPos);
        #endregion

        #region 构造函数
        /// <summary>
        /// 构建ScrollableControl
        /// </summary>
        public ScrollableControl()
        {
            Handle = UiScrollWinWrapperCtor(LButtonDbClkDelegate, LButtonDownDelegate,
                LButtonUpDelegate, MouseMoveDelegate);
            SetID();
            NotifyMessage = true;// 默认启用鼠标通知
        }
        #endregion

        #region 函数
        /// <summary>
        /// 将控件内容滚动到指定位置（垂直方向）
        /// </summary>
        /// <param name="nOffset"></param>
        public void Scroll(int nOffset)
        {
            UiScrollWinWrapperScroll(Handle, nOffset);
        }
        /// <summary>
        /// 将控件内容移动到指定位置（垂直方向）
        /// </summary>
        /// <param name="nOffset"></param>
        public void MoveTopPos(int nOffset)
        {
            UiScrollWinWrapperMoveTopPos(Handle, nOffset);
        }
        /// <summary>
        /// 设置内容顶部位置
        /// </summary>
        /// <param name="nTopPos"></param>
        public void SetTopPos(int nTopPos)
        {
            UiScrollWinWrapperSetTopPos(Handle, nTopPos);
        }
        /// <summary>
        /// 开始滚动
        /// </summary>
        /// <param name="scrollSpeed">滚动速度</param>
        public override void ScrollStart(double scrollSpeed)
        {
            UiScrollWinWrapperScrollStart(Handle, scrollSpeed);
        }
        /// <summary>
        /// 停止滚动
        /// </summary>
        public override void ScrollStop()
        {
            UiScrollWinWrapperScrollStop(Handle);
        }
        /// <summary>
        /// 滚动列表内容到指定位置
        /// </summary>
        /// <param name="scrollType">滚动类型</param>
        /// <param name="dstTopPos">目的位置。当ScrollType=ScrollToPos时才有效</param>
        /// <param name="animate">是否显示滚动过程</param>
        public override void ScrollTo(ScrollType scrollType, int dstTopPos, bool animate)
        {
            UiScrollWinWrapperScrollTo(Handle, (int)scrollType, dstTopPos, animate);
        }
        /// <summary>
        /// 处理消息
        /// </summary>
        /// <param name="message"></param>
        /// <param name="wParam"></param>
        /// <param name="lParam"></param>
        protected override void WndProc(uint message, uint wParam, uint lParam)
        {
            base.WndProc(message, wParam, lParam);
        }
        #endregion
    }
}
